#!/bin/bash

set -e
set -x

bypy download jdk-17.0.13_linux-x64_bin.tar.gz

iplist_path=config
while read -r line
do
    case $line in
        *'#'*)
            continue
        ;;
        *'end'*)
            break
        ;;
        *)
            IFS=',' read -ra parts <<< "$line"
        ;;
    esac
    
    pass="${parts[0]}" 
    address="${parts[1]}"
    hostname="${parts[2]}"
    if [ $address ];then
        sshpass -p$pass scp jdk-17.0.13_linux-x64_bin.tar.gz $address:/opt/
        sshpass -p$pass ssh -n $address tar xf /opt/jdk-17.0.13_linux-x64_bin.tar.gz -C /opt/
        sshpass -p$pass scp java_env.sh $address:/etc/profile.d/java_env.sh
        sshpass -p$pass ssh -n $address ln -fs /opt/jdk-17.0.13/bin/java /usr/local/bin/java
    fi
done < $iplist_path

set +x
set +e
